package com.shlg.chuang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.shlg.chuang.domain.ShowUser;
import com.shlg.chuang.service.ShowUserService;

@RestController
@RequestMapping(value = "/showUsers")
public class UserController {
	
	@Autowired
	ShowUserService showUserService;
	
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public ShowUser register(@RequestBody ShowUser showUser) {
		return showUserService.saveShowUser(showUser);
	}
	
	@RequestMapping(value = "login", method = RequestMethod.GET)
	public ShowUser login(@Param(value = "email") String email, 
			@Param(value = "password") String password) {
		return showUserService.getShowUserByEmailAndPassword(email, password);
	}
	
	@RequestMapping(value = "/modifyUser", method = RequestMethod.POST)
	public ShowUser modifyUser(@RequestBody ShowUser showUser) {
		return showUserService.saveShowUser(showUser);
	}
	
	@RequestMapping(value = "checkedRepeat", method = RequestMethod.GET) 
	public ShowUser checkedRepeat(@Param(value = "email")String email){
		return showUserService.findByEmail(email);
	}
	
	@RequestMapping(value = "findOne", method = RequestMethod.GET)
	public ShowUser findOne(@Param(value = "showUserId") Long showUserId) {
		return showUserService.findById(showUserId);
	}
	
	@RequestMapping(value = "deleteOne", method = RequestMethod.GET) 
	public String deleteOne(@Param(value = "showUserId") Long showUserId) {
		showUserService.deleteShowUser(showUserId);
		return "Your selected is deleted";
	}

}
